package com.pehulja.mmdo.coursework.math;

import com.pehulja.mmdo.coursework.math.exceptions.InvalidNumberArgmentsException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Class thet exneds Polinomial function adding extremum sight to it
 */
public class GoalFunction extends PolinomialFunc implements Serializable{
    public static enum Extremum {Min, Max};
    private Extremum extremum;

    public GoalFunction(double[][] data, Extremum extremum) throws InvalidNumberArgmentsException {
        super(data);
        this.extremum = extremum;
    }

    public GoalFunction() {

    }

    public Extremum getExtremum() {
        return extremum;
    }

    public void setExtremum(Extremum extremum) {
        this.extremum = extremum;
    }
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(super.toString());
        if(extremum != null){
            if(extremum == Extremum.Max)
                builder.append(" -> Max");
            else
                builder.append(" -> Min");
        }
        return builder.toString();
    }
    
    public GoalFunction copy(){
        GoalFunction function = new GoalFunction();
        List <Term> list = new ArrayList<Term>();
        for(Term term:this.getComponents())
            list.add(term.copy());
        function.setComponents(list);
        function.setExtremum(this.getExtremum());
        return function;
    }
}
